package com.tbit.api;

import com.tbit.common.entity.pojo.dto.ReturnBikeMsgLogDTO;
import com.tbit.common.entity.pojo.vo.HeatMapStatVO;
import com.tbit.common.entity.pojo.vo.ParkPointCoreDataVO;
import com.tbit.common.entity.pojo.vo.ReturnBikeMsgLogVO;
import com.tbit.manager.api.ParkPointOAServiceApi;
import com.tbit.uqbike.object.business.Point;
import com.tbit.uqbike.object.pojo.HeatMapStat;
import com.tbit.uqbike.service.base.CalibrateService;
import com.tbit.uqbike.service.base.ParkPointService;
import com.tbit.uqbike.service.business.operationsanalysis.ParkPointOAService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 运营分析-站点分析
 *
 * @author ：zhangtianyou
 * @since 2025/3/13
 */
@RestController
public class ParkPointOAServiceApiImpl implements ParkPointOAServiceApi {

    @Autowired
    private ParkPointOAService parkPointOAService;
    @Autowired
    private ParkPointService parkPointService;
    @Autowired
    private CalibrateService calibrateService;

    @Override
    public ParkPointCoreDataVO getCoreData(Integer accountId, Date startTime, Date endTime) {
        return parkPointOAService.getCoreData(accountId, startTime, endTime);
    }

    @Override
    public List<ReturnBikeMsgLogVO> getApplyReturnBikePoint(ReturnBikeMsgLogDTO returnBikeMsgLogDTO) {
        return parkPointOAService.getApplyReturnBikePoint(returnBikeMsgLogDTO);
    }

    @Override
    public List<HeatMapStatVO> statHeatMap(Integer accountId, long startTime, long endTime, Integer type, Integer mapType, String regionIds) {
        List<HeatMapStat> heatMapStatList = parkPointService.statByPark(accountId, type, startTime, endTime, regionIds);

        if (!CollectionUtils.isEmpty(heatMapStatList)) {
            /**经纬度校准*/
            for (HeatMapStat heat : heatMapStatList) {
                Point point = calibrateService.calibrateOffSet(heat.getLng(), heat.getLat(), mapType);
                heat.setLng(point.getX());
                heat.setLat(point.getY());
            }
        }

        List<HeatMapStatVO> heatMapStatVOList = heatMapStatList.stream()
                .map(item -> {
                    return new HeatMapStatVO(item.getCount(), item.getLng(), item.getLat());
                })
                .collect(Collectors.toList());
        return heatMapStatVOList;
    }
}
